{% set access_data = access_interfaces[inventory_hostname] %}
{% set all_vlans = access_data | map(attribute='vlan') | list %}
{% for vlan in all_vlans %}
!
vlan {{ vlan }}
   name VLAN_{{ vlan }}
{% endfor %}
!
!
interface Vxlan1
   vxlan source-interface Loopback0
   vxlan udp-port 4789
{% for vlan in all_vlans %}
   vxlan vlan {{ vlan }} vni 10{{vlan}}
{% endfor %}
!
!
{% for port in access_data|sort(attribute='name') %}
interface {{ port.name }}
   description "Access"
{% if port.mode == 'access' %}
   switchport mode access
   switchport access vlan {{port.vlan}}
{% else %}
   switchport mode trunk
   switchport trunk allowed vlan {{port.vlan}}
{% endif %}
{%  endfor %}
!

!
router bgp {{bgp_asn}}
!
{% for vlan in all_vlans %}
  vlan {{ vlan }}
      rd {{lo_ip[inventory_hostname].split('/')[0]}}:10{{vlan}}
      route-target both 10{{vlan}}:10{{vlan}}
      redistribute learned
{%  endfor %}
   !
!